package cn.com.pajx.pajx_visitor_v3.ui.view;

import android.annotation.SuppressLint;
import android.os.CountDownTimer;
import android.widget.TextView;

public class TimerCount extends CountDownTimer {

    private final TextView tvTimer;

    public TimerCount(long millisInFuture, long countDownInterval, TextView tvTimer) {
        super(millisInFuture, countDownInterval);
        this.tvTimer = tvTimer;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onTick(long millisUntilFinished) {
        if (tvTimer != null) tvTimer.setText(millisUntilFinished / 1000 + "S后关闭");
        if (onTimerFinish != null && millisUntilFinished / 1000 == 1) onTimerFinish.timerFinish();
    }

    @Override
    public void onFinish() {

    }

    private OnTimerFinish onTimerFinish;

    public interface OnTimerFinish {
        void timerFinish();
    }

    public void setOnTimerFinish(OnTimerFinish onTimerFinish) {
        this.onTimerFinish = onTimerFinish;
    }
}
